<?php
error_reporting("E_ALL");ini_set("display_errors", 1);
$getdata=$_REQUEST;
if(empty($getdata))$getdata=$_POST?$_POST:$_GET;
$type=empty($getdata['type'])?'':$getdata['type'];
include("include/function.php");
//header("content-Type: application/json; charset=utf-8");
$config = include("config.php");
include("include/".$config['DB_TYPE'].".class.php");
$db = new db;
$db->connect($config['DB_HOST'],$config['DB_USER'],$config['DB_PWD'],$config['DB_NAME'], $config['DB_PCONNECT']);
      
$page = empty($getdata['page'])?1:$getdata['page'];
$id = empty($getdata['id'])?0:$getdata['id'];
$length=200;
$where="F9!=''";
$orderids=[];
$insert=0;
$sql="select * from shanghu where ".$where.' limit '.$length;
$list = $db->get_all($sql);if(empty($list))exit('over');

$sql="select name,mch_id from hema_school where status=1";
$schoolname = $db->get_all($sql);$schoolnames=[];foreach($schoolname as $v){$schoolnames[$v['name']]=$v['mch_id']?$v['mch_id']:1;};
$ssql=[];$noschool=[];$nomch=[];
foreach($list as $v){if(empty($v['F3']))continue;
        if(empty($schoolnames[$v['F3']])){
            $noschool[]=$v['F3'];
        }else{
            if($schoolnames[$v['F3']]!=$v['F8'])$nomch[]=$v['F3'];
        }
    
    
        $data=[];
        $data['mch_id']=$data['alimch_id']=$v['F8'];if(empty($data['mch_id']))continue;
        $data['mch_name']=$data['alimch_name']=$v['F7'];
        if(!empty($v['F10']))$data['bank_name']=$v['F10'];
        if(!empty($v['F9']))$data['bank_sn']=$v['F9'];
        if(!empty($v['F13']))$data['contact']=$v['F13'];
        if(!empty($v['F14']))$data['phone']=$v['F14'];
        $sdata=[];
        foreach($data as $k1=>$v1){
            $sdata[]="`".$k1."`='".$v1."'";
        }
        $ssql[] = "update hema_school set ".implode(',',$sdata)." where mch_id='' and name='".$v['F3']."';";
        
}
echo count($ssql)."<br>\n";
echo '$noschool:';print_r($noschool);
echo '$nomch:';print_r($nomch);

//echo implode("\n",$ssql);
//$log = $id.'导入成功,处理：'.$insert.'条';
//echo $log.'<script>location.href="?page='.$page.'&id='.$id.'";</script>';

//echo count($sqlarr)."\n";
//echo implode(";\n",$sqlarr);
?>